package controllers

import (
	"ShopSupplierApi/models"
	"ShopSupplierApi/services"
	"ShopSupplierApi/utils"
)

//MembersController 会员
type MembersController struct {
	LcfController
}

// @Title   获取基本会员信息
// @Param   mid query   uint64  true    "会员ID"
// @Success 200
// @router /simpleMemberInfo [get]
func (c *MembersController) SimpleMemberInfo() {
	mid, err := c.GetInt64("mid")
	if err != nil {
		c.JSONFailedError(utils.LoseParam("mid[用户ID]"))
		return
	}
	c.JSONSuccess(services.MemberServ.SimpleMemberInfo(uint64(mid)))
}

// @Title 获取会员列表
// @Param sid   query   uint64  true    "供应商ID"
// @Param mType query   models.MemberType   true    "会员类型"
// @Param search query  string  false   "搜索关键字"
// @Param   p   body   *models.Page true    "分页数据信息"
// @Success 200
// @router /memberList [post]
func (c *MembersController) MemberList() {
	sid, err := c.GetInt64("sid")
	if err != nil {
		c.JSONFailedError(utils.NotFoundSid)
		return
	}
	mType, _ := c.GetInt("mType")
	mt := models.MemberType(mType)
	search := c.GetString("search")
	err = c.ParseBodyToPage()
	if err != nil { //分页数据解析错误,直接返回
		return
	}
	c.JSONPageData(services.MemberServ.MemberList(uint64(sid), mt, search, c.Data["page"].(*models.Page)))
}

// @Title 货品购买者会员列表
// @Param sid   query   uint64  true    "供应商ID"
// @Param pid query   uint64   true    "货品ID"
// @Param   p   body   *models.Page true    "分页数据信息"
// @Success 200
// @router /productMemberList [post]
func (c *MembersController) ProductMemberList() {
	sid, err := c.GetInt64("sid")
	if err != nil {
		c.JSONFailedError(utils.NotFoundSid)
		return
	}
	pid, err := c.GetInt64("pid")
	if err != nil {
		c.JSONFailedError(utils.LoseParam("pid[货品ID]"))
		return
	}
	err = c.ParseBodyToPage()
	if err != nil { //分页数据解析错误,直接返回
		return
	}
	c.JSONPageData(services.MemberServ.ProductMemberList(uint64(sid), uint64(pid), c.Data["page"].(*models.Page)))
}
